24. [Optional] Cars and Conditional Probability
Cars and Conditional Probability
So far you have gotten a glimpse of how probability is used in self-driving cars when events are independent from each other. However, in many cases, the previous event helps shape the probability of the current event. In this case, these events are said to be conditional, meaning they are affected by another (usually previous) event. This is a bit of a tricky nuance so let us spend some time trying to build some intuition.
** If you are already comfortable with conditional probability, please feel free to skip these exercises. **
Here is a real-problem that plagues many self-driving cars. Suppose your self-driving car and another car arrive at a four-way stop. The rules of the road state that the car that arrives at the stop sign first has the right of way to continue through the intersection before the other car. Unfortunately, sometimes this is hard to determine because two cars appear to get to the stop sign at the same time. Additionally, sometimes, the car that arrives second will actually go before the car that arrives first (thus breaking the law).
Conditional Probability
QUESTION:
Suppose your car and another car arrive at the intersection at roughly the same time. The probability you arrived first is 0.6. What is the probability that the other car arrived first?
SOLUTION:
NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer
At this point you know have several scenarios. You could arrive first, or you could arrive second. If you arrive first, you could go first or second, and similar for arriving second. However, the action of going is dependent on whether you arrived first or second.
This is called conditional probability, and can be denoted as P(X|Y) (read as "the probability of X given Y").
Conditional Probability 2
QUESTION:
Assume P(\textrm{Go First} | \textrm{Arrived First}) = 0.8. What is the P(\textrm{Go Second} | \textrm{Arrived First})?
SOLUTION:
NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer
Conditional Probability 3
QUESTION:
Assume P(\textrm{Go First} | \textrm{Arrived Second}) = 0.9. What is the P(\textrm{Go Second} | \textrm{Arrived Second})?
SOLUTION:
NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer
Now, let’s calculate the conditional probability of some events. In order to do this we need the following formula:
P(A|B) = P(A \cap B) / P(B)
What this means in English is given an event B, find all the events shared with A, and divide by the probability of event B happening by itself. The \cap symbol for intersection represents these events shared between A & B.
When dealing with these probabilities, the basic rules of algebra apply so we manipulate the equation by multiplying both sides by \small P(B) to also look like this:
P(A \cap B) = P(A|B) * P(B)
Other formulations are also valid provided you adhere to the algebraic rules, but these two equations should be sufficient for many of your needs.
Conditional Probability 3
QUESTION:
Assume:
P(Arrive First) = 0.9
P(Arrive Second) = 0.1
P(Go First | Arrive Second) = 0.1
P(Go Second | Arrive Second) = 0.9
P(Go First | Arrive First) = 0.8
P(Go Second | Arrive First) = 0.2
Using the formula P(A \cap B) = P(A|B) * P(B)
What is P(\textrm{You Go First} \cap \textrm{You Arrived First})?
SOLUTION:
NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer
Law of Total Probability
A useful law when dealing with conditional probability is the Law of Total Probability.
If B_1, B_2, B_3, … is a partition of a sample space S, then for any event A:
P(A)=\sum_i P(A \cap B_i) = \sum_i P(A | B_i) * P(B_i)
The formal definition is a bit "mathy", but think of it as calculating the sum of all probabilities necessary to ensure all scenarios for specified event are included. This is actually quite similar to the equation from before, but now we calculate it for each i of B, and then sum all of these together.
Total Probability
QUESTION:
Recalling the previous values from above:
P(Arrive First) = 0.6
P(Arrive Second) = 0.4
P(Go First | Arrive First) = 0.8
P(Go Second | Arrive First) = 0.2
P(Go First | Arrive Second) = 0.1
P(Go Second | Arrive Second) = 0.9
What is P(\textrm{Go First})? (Decimal only)
SOLUTION:
NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer